import uuid
import os
from time import ctime

class Logger:
    def __init__(self):
        d = os.path.dirname("Logs/")
        if not os.path.exists(d):
            os.makedirs(d)
        self.guid = str(uuid.uuid1())
        self.logFile="Logs/"+self.guid+".txt"
        self.log(Tags.getTag(1), 0, "Logging Started")
    #tag can equal SUCCESS or ERROR or LOG
    #errno is the error number, 0 means success
    def log(self, tag, errno="0", strText="", stackDump=""):
        f = open(self.logFile,'a')
        f.write("[%s], %s, %s, %s, %s\n"%(ctime(), tag, errno, strText, stackDump))
        f.close()
    def logError(self, errno="1", strText="", stackDump=""):
        self.log(Tags.getTag(2),errno, strText, stackDump)
    def logLog(self, errno="0", strText="", stackDump=""):
        self.log(Tags.getTag(1),errno, strText, stackDump)

class Tags:
    SUCCESS=0
    LOG=1
    ERROR=2
    @classmethod
    def getTag(cls,tag):
        if tag==cls.SUCCESS:
            return "SUCCESS"
        elif tag==cls.LOG:
            return "LOG"
        elif tag==cls.ERROR:
            return "ERROR"
